<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/3/12
 * Time: 14:14
 */

namespace app\admin\controller;
use \think\Request;
use app\common\model\Feedback as FeedbackModel;
use app\common\model\Edition as EditionModel;
use think\Db;
class Feedback extends \app\admin\controller\Base
{
    protected $res = array(
        'index'   => array('css' => '2,3,4', 'js' => 'list,My97DatePicker'),
        'logo'   => array('css' => '2,3,4', 'js' => 'list'),
        'add'   => array('css' => '2,3,4,5,9','js'=>''),
        'save'   => array('css' => '2,3,4,5,9','js'=>'list')
    );
    /**
     * 反馈首页列表
     * @return mixed
     */
    public function index(){
        $FeedbackModel = new FeedbackModel();
        $search = input('param.search/a');
        $page = input('param.page');
        $list = $FeedbackModel->getFeedback($search, $page);
        $this->assign(
          array(
              'list'               =>     $list,
              'feedback_status'    =>     $FeedbackModel::$feedback_status,
              'search'             =>     $search
          )
        );
        return $this->fetch();
    }
    /**
     * 反馈详情
     */
    public function details(){
        $FeedbackModel = new FeedbackModel();
        $feedback_id = input('param.feedback_id');
        $list = $FeedbackModel->getContent($feedback_id);
        $this->assign(
            array(
                'list'             =>    $list,
                'feedback_status'  =>    $FeedbackModel::$feedback_status
            )
        );
        return $this->fetch();
    }
    /**
     * logo
     */
    public function logo(){
        $EditionModel = new EditionModel();
        $page = input('param.page');
        $list = $EditionModel->getList($page);
        $this->assign(
          array(
              'list'      =>      $list
          )
        );
        return $this->fetch();
    }
    /**
     * logo添加
     */
    public function add(){
        $editionModel = new EditionModel();
        if(Request::instance()->isPost()){
            if($_FILES['file']['name'][0] == ''){
                return $this->api_dbError("上传文件不能为空");
            }
            $rand = date('YmdHis').rand(100000,999999);
            $exe = explode('.',$_FILES['file']['name'][0]);
            $filePath = $_FILES['file']['tmp_name'][0];
            $info = $this->qnCommon($rand,$exe[1],$filePath);
            if($info['status']!=200) {
                return $this->api_dbError("上传文件格式不正确");
            }
            $data['edition_log'] = QiNiu.$info['key'];
            $res = $editionModel->add($data);
            if ($res) {
                $this->Jpush('','发布新版本',2, array('type'=>2));
                return $this->api_success("操作成功");
            } else {
                return $this->api_dbError("操作失败");
            }
        }
        return $this->fetch();

    }
	
	
	
	
	
	
	//public function huifu()
	//{
	//	set_time_limit(0);
	//	$res = Db::table('up_u_user')->field('user_id,user_image')->select();
	//	foreach($res as $k=>$v){
	//		$img = trim($v['user_image'],',');
	//		if($img){
	//			if(strpos($img,'http://p5x5q4kdj.bkt.clouddn.com') !== false){
	//						$new = str_replace("http://p5x5q4kdj.bkt.clouddn.com","http://qiniu2.yi-dog.com",$img);
	//						Db::table('up_u_user')->where('user_id',$v['user_id'])->update(['user_image'=>$new]);
	//					}
	//			//$array = explode(',',$img);
	//			//foreach($array as $kk=>$vv){
	//			//		if(strpos($vv,'http://p5x5q4kdj.bkt.clouddn.com') !== false){
	//			//			$new = str_replace("http://p5x5q4kdj.bkt.clouddn.com","http://qiniu2.yi-dog.com",$vv);
	//			//			$array[$kk] = $new;
	//			//		}
	//			//	}
	//			//$newimg = implode($array,',');
	//			//Db::table('up_dog_family')->where('udf_id',$v['udf_id'])->update(['udf_img'=>$newimg]);
	//			
	//		}
	//		
	//		
	//	}
	//	return 1;
	//}
	
	
}